package org.ourgrid.broker.business.schedulerdata.executor;

import java.io.Reader;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.ourgrid.common.logger.NoOpEntityResolver;
import org.ourgrid.common.util.StringUtil;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

public abstract class AbstractSchedulerDataExecutor implements SchedulerDataExecutorIF {
	protected Document getXMl(String xml) {
		
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		
		Document logDocFile = null;
		try {
			DocumentBuilder docBuilder = dbf.newDocumentBuilder();
			docBuilder.setEntityResolver(new NoOpEntityResolver());
			
			Reader reader = new StringReader(xml);
			InputSource s = new InputSource(reader);
			logDocFile = docBuilder.parse(s);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return logDocFile;
	}
	
	protected String getAddress(String id) {
		return StringUtil.deploymentIDToAddress(id);
	}
}
